package com.lm.scau.framedemos;

import android.app.Activity;
import android.app.Application;

import java.util.LinkedList;
import java.util.List;

/**
 * Function:
 * auth：liming on 2016/5/24 09:37
 * mail：liming@wxchina.com
 */
public class ScauApplication extends Application {
    private List<Activity> mList;
    private static ScauApplication mApplication;

    public ScauApplication(){
        mList = new LinkedList<>();
    }
    @Override
    public void onCreate() {
        super.onCreate();

    }

    public synchronized static ScauApplication getInstance() {
        if (null == mApplication) {
            mApplication = new ScauApplication();
        }
        return mApplication;
    }

    public void addActivity(Activity activity) {
        if (null != activity && !mList.contains(activity)) {
            mList.add(activity);
        }
    }

    public void exit() {
        try {
            for (Activity activity : mList) {
                if (activity != null)
                    activity.finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.exit(0);
        }
    }

}
